ComponentOne Data Source for Entity Framework
C1.LiveLinq.LiveViews Namespace / View<T> Class / AttachView Method / AttachView<TResult>(Func<View<T>,View<TResult>>) Method
The type of the elements in the subquery view.
A function to obtain the attached subview from the view to which it is attached.
Example

In This Topic
    AttachView<TResult>(Func<View<T>,View<TResult>>) Method
    In This Topic
    Includes a subquery into the incremental maintenance mechanism of a view.
    Syntax
    'Declaration
     
    
    Public Overloads Function AttachView(Of TResult)( _
       ByVal selector As System.Func(Of View(Of T),View(Of TResult)) _
    ) As View(Of TResult)
    public View<TResult> AttachView<TResult>( 
       System.Func<View<T>,View<TResult>> selector
    )

    Parameters

    selector
    A function to obtain the attached subview from the view to which it is attached.

    Type Parameters

    TResult
    The type of the elements in the subquery view.

    Return Value

    The attached subview.
    Remarks

    Subquery is a query inside a function that is a part of an outer query. If the outer query is a live view, and its base data changes so it needs to recompute the function, by default it just evaluates the function, which means creating a new view object for the subquery on every such recomputation. To improve performance by avoiding repeated creation and population of subviews, use the AttachView method to make the outer view aware of its subview. Then the outer view will cache and reuse subview objects it creates.

    If there are more than one subviews attached to a single view, every subview must be supplied with a unique subview id by using the AttachView overload with subviewId parameter.

    var productView = from p in products join s in sales on p.ProductID equals s.ProductID into productSales select new { p.Name, SalesByCountry = productSales.AttachView(v => from s in v group s by s.Country into countrySales select new { Country = countrySales.Key, SaleCount = countrySales.LiveSum(s => s.Quantity).Value }) };
    Example
    var productView =
        from p in products
        join s in sales on p.ProductID equals s.ProductID into productSales
        select new
        {
            p.Name,
            SalesByCountry = productSales.AttachView(v =>
                from s in v
                group s by s.Country into countrySales
                select new
                {
                    Country = countrySales.Key,
                    SaleCount = countrySales.LiveSum(s => s.Quantity).Value
                })
        };
    See Also